/**
 * Inject dependanceies into index.html, HTML TASK
 * @Author: jiangcheng198745@hotmail.com
 * @Date: 2016/07/06
 */
'use strict';

import gulp from 'gulp';
import rename from 'gulp-rename';
import inject from 'gulp-inject';
import {argv as args} from 'yargs';
import {reload} from 'browser-sync';
import runSeq from 'run-sequence';
import series  from 'stream-series';

import messageLogger from '../utils/message.gulp';
import config from '../gulp.config';

gulp.task('processHTML:build', (done) => {
    runSeq(['index:build'], done);
});

gulp.task('index:build', () => {

    let jsFiles  = config.build + '/' + config.distEntry;

    let cssFile = config.build + '/' + config.css + '/' + config.cssName + '.css';

    return gulp.src(config.app + '/index.html')
        .pipe(inject(
            series(
                gulp.src(config.vendorFiles.css, {
                    read: false
                }),
                gulp.src(cssFile, {
                    read: false
                })
            ), {
            ignorePath: config.build,
            addRootSlash: false
        }))
        .pipe(inject(
            series(
                gulp.src(config.vendorFiles.js, {
                    read: false
                }),
                gulp.src(jsFiles, {
                    read: false
                })
            ), {
               ignorePath: config.build,
                addRootSlash: false 
            }
        ))
        .pipe(rename('index.html'))
        .pipe(gulp.dest(config.build))
        .pipe(reload({
            stream: true
        }));
});


